import { useEffect } from "react"
import SyntaxHighlighter from '@/components/SyntaxHighlighter'

const code1 = `
  const setFn = () => {
    const arr = [1, 0, 2, 0, 0, 3]
    const result = []

    arr.forEach(item => {
      if (item === 0) {
        result.push(item)
      } else {
        result.unshift(item)
      }
    })

    console.log('result', result)
  }
`

function ZeroToEnd() {

  const setFn = () => {
    const arr = [1, 0, 2, 0, 0, 3]
    const result = []

    arr.forEach(item => {
      if (item === 0) {
        result.push(item)
      } else {
        result.unshift(item)
      }
    })

    console.log('result', result)
  }

  useEffect(() => {
    setFn()
  }, [])

  return (
    <div>
      <p>把数组中的零放到末尾</p>
      <p>代码实现逻辑：</p>
      <SyntaxHighlighter children={code1} />
    </div>
  )
}

export default ZeroToEnd